<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/pages/common/taglib.jsp"  %>
<%@include file="/pages/common/tagjs.jsp"  %>
<%@include file="/WEB-INF/tags/gfa4ext/inc/extmeta.jsp"  %>
<%@ taglib tagdir="/WEB-INF/tags/gfa4ext" prefix="ge" %>
<html>
<head>
<script type="text/javascript">
Ext.onReady( function() {

	var isAdd = 0;// 新增的时候是1
	
	var OfficeRec = Ext.data.Record.create( [ 'officeCode', 'officeType',
		'officeName', 'businessRegisterNo', 'superiorOfficeCode',
		'email', 'tel', 'fax', 'active',
		'homeCurrency', 'officeNativeName', 'abbrev',
		'taxRegisterNo', 'isCustomer', 'language', 'deleted']);
		
	var root = new Ext.tree.TreeNode( {
		expanded : true
	});

	var authTree = new Ext.tree.TreePanel( {
		el : 'tree',
		margins : '5 0 5 5',
		region : 'west',
		width : 150,
		minSize : 175,
		maxSize : 400,
		border : true,
		rootVisible : false,
		autoScroll : true,
		text : '',
		root : root
		
	});

	var nodes = [];

	OfficeService.getOfficeTreeAll({
		callback : function(result) {
			Ext.each(result, function(func) {
				var nodeFunction = new Ext.tree.TreeNode({
					id : 'sys-' + func.officeCode,
					iconCls : 'k-tree',
					text : func.officeName
				});

				nodeFunction.data = func;
				root.appendChild(nodeFunction);
				nodes.push(nodeFunction);
			});
		},
		async : false
	});

	for ( var i = 0; i < nodes.length; i++) {
		//alert(i);
		var node = nodes[i];
		var func = node.data;
		// 
		if (func.superiorOfficeCode && func.superiorOfficeCode != func.officeCode) {
				var parentNode = authTree.getNodeById('sys-' + func.superiorOfficeCode);
				if (parentNode != null && parentNode != undefined) {
					root.removeChild(node);
					parentNode.appendChild(node);
				} else {
					//root.removeChild(node);
				}
		}
	}

	authTree.render();

	authTree.on('click', function(node) {
			
			var officeId=node.data.officeId;//取得officeId
			alert(officeId);
			//formModule.editingRec = new OfficeRec(node.data);
			controlEnable();
			//根据officeId 查询信息
			dsSysHub.load( {
				params : {
					dwrMethod : "findByProperty",
					dwrArguments : [{
						queryObjectName : 'com.wef.system.entity.Office',
						listType : 'Office',
						whereCondition : 'officeId=\''+officeId+'\''
					}]
				}
			});
		});
});

$(function(){
	$("#officeCodeSelsect").autoSelect({
		url : "${ctx}",
		className:"com.wef.system.entity.Office",
		displayField : "officeName",
		width : 450,
		displayNum : 8,
		inTable : false,
		hiddenId : 'officeId',
		canNotInput : true
		
	});
});

function deleteAction(event,id){
	alert(123);
   TableUtils._cancelBubble(event);
	if(!window.confirm("<bean:message key='singleStruts.delete' bundle='i18n.demo' />")){
	    return false;
	}else{
	    try{
		  window.location="office.do?method=delete&officeId="+id;
		}catch(e){
		  alert(e);
		}finally{
		}
	}
}
	
</script>

</head>
<body>
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="1">
<tr>
	<td width="182" height="50%">
		<div id="tree" style="width:90%;height:90%"></div>	
	</td>
	
	<td width="1" >&nbsp;</td>
	
	<td height="100%">
		<div id="officeManagerEditDiv" class="ModuleEdit">
			 <div class="ModuleEditBorder">
					<div class="ModuleEditButton">
						<!--按钮 -->
					    <g:button styleId="btnSave" styleClass="new" type="button" text="button.save" onclick=""/>
						<!--按钮 -->
					    <g:button styleId="btnNew" styleClass="delete" type="button" text="button.new" onclick ="javascript:FormUtils.clearForm('editForm');"/>
						<!--按钮 -->
					    <g:button styleId="btnDelete" styleClass="cancel" type="button" text="button.delete" onclick = "deleteAction();"/>
					    <!--按钮 -->
					    <g:button styleId="btnCancel" styleClass="cancel" type="button" text="button.cancel"/>
					</div>
					<div class="Line"></div>
					<div id="editFormDiv">
					    <form id="editForm" onsubmit="return false;">
						<table width="100%" class="ModuleEditInput">
								<tr>
									<td width="10%"><g:label text="system.office.officeCode"/></td>
									<td width="22%"><g:text property="officeCode"></g:text></td>
									<td width="10%"><g:label text="system.office.officeName"/></td>
									<td width="22%"><g:text property="officeName"/></td>
									<td width="10%"><g:label text="system.office.address"  /></td>
									<td width="22%"><g:text property="address"/></td>
								</tr>
								<tr>
									<td width="10%"><g:label text="system.office.homeCurrency " /></td>
									<td width="22%"><g:text property="homeCurrency"></g:text></td>
									<td width="10%"><g:label text="system.office.xchgrName"/></td>
									<td width="22%"><g:text property="xchgrName"/></td>
									<td width="10%"><g:label text="system.office.officeType"  /></td>
									<td width="22%">
									<g:combox kind="select" property="officeType">
											<g:option value="1">AGENT</g:option>
											<g:option value="2">COMPANY</g:option>
											<g:option value="3">DEPARTMENT</g:option>
											<g:option value="4">OFFICE</g:option>
										</g:combox>
									</td>
								</tr>	
								<tr>
									<td width="10%"><g:label text="system.office.language "/></td>
									<td width="22%"><g:text property="language"></g:text></td>
									<td width="10%"><g:label text="system.office.tel"/></td>
									<td width="22%"><g:text property="tel"/></td>
									<td width="10%"><g:label text="system.office.fax "  /></td>
									<td width="22%"><g:text property="fax"/></td>
								</tr>
								<tr>
									<td width="10%"><g:label text="system.office.settleOffice"/></td>
									<td width="22%"><g:text property="settleOffice"></g:text></td>
									<td width="10%"><g:label text="system.office.taxRegisterNo"/></td>
									<td width="22%"><g:text property="taxRegisterNo"/></td>
									<td width="10%"><g:label text="system.office.businessRegisterNo"  /></td>
									<td width="22%"><g:text property="businessRegisterNo"/></td>
								</tr>
								<tr>
									<td width="10%"><g:label text="system.office.officeNativeName"/></td>
									<td width="22%"><g:text property="officeNativeName"></g:text></td>
									<td width="10%"><g:label text="system.office.abbrev"/></td>
									<td width="22%"><g:text property="abbrev"/></td>
									<td width="10%"><g:label text="system.office.email"  /></td>
									<td width="22%"><g:text property="email"/></td>
								</tr>
								<tr>
									<td width="10%"><g:label text="system.office.superiorOfficeCode"/></td>
									<td width="22%"><g:combox kind="associate" styleId="officeCodeSelsect" property="superiorOfficeCode"></g:combox></td>
									<td width="10%"><g:label text="system.office.isCustomer"/></td>
									<td width="22%"><g:checkbox property="isCustomer"/></td>
									<td width="10%"><g:label text="system.office.active"  /></td>
									<td width="22%"><g:checkbox property="active"/></td>
								</tr>
								<tr>
									<td width="10%"><g:label text="system.office.deleted " /></td>
									<td width="22%"><g:checkbox property="deleted"></g:checkbox></td>
									<td width="10%">&nbsp;</td>
									<td width="22%">&nbsp;</td>
									<td width="10%">&nbsp;</td>
									<td width="22%">&nbsp;</td>
								</tr>
						</table>
						</form>
					</div>
			</div>
				  <!-- 编辑区域 -->
		
		</div>
	</td>
</tr>
</table>

</body>
</html>